package com.example.thecv;

import java.util.Random;

import android.os.Bundle;
import android.provider.ContactsContract;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.QuickContactBadge;
import android.widget.TextView;

public class Info extends Activity {

	@Override
	public void onBackPressed() {
		Intent i = new Intent(this, MainActivity.class);
    	startActivity(new Intent(i));
		return;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_info);
		
		Intent i = getIntent();
		final String currentCV = i.getStringExtra("currentCV");
		
		QuickContactBadge badgeSmall = (QuickContactBadge) findViewById(R.id.photo);
		int photo = 0;
		String email = "";
		int info = 0;
		int name = 0;
		
		if (currentCV.equals("jason")) {
			photo = R.drawable.jason;
			email = "jasonwheatcraft@gmail.com";
			info = R.array.jason_array;
			name = R.string.jason;
		} else if (currentCV.equals("johan")) {
			photo = R.drawable.johan;
			email = "johan.krznaric@gmail.com"; 
			info = R.array.johan_array;
			name = R.string.johan;
		} else if (currentCV.equals("jimmy")) {
			photo = R.drawable.jimmy;
			email = "jimmypersson1986@gmail.com"; 
			info = R.array.jimmy_array;
			name = R.string.jimmy;
		} else if (currentCV.equals("ali")) {
			photo = R.drawable.ali;
			email = "aliman@live.se"; 
			info = R.array.ali_array;
			name = R.string.ali;
		} else if (currentCV.equals("hammad")) {
			photo = R.drawable.hammad;
			email = "hammad.oth@gmail.com";
			info = R.array.hammad_array;
			name = R.string.hammad;
		}
		
		final String[] infoArray = getResources().getStringArray(info);
		
		badgeSmall.setImageResource(photo);
		badgeSmall.assignContactFromEmail(email, true); 
		badgeSmall.setMode(ContactsContract.QuickContact.MODE_SMALL);
		
		((TextView) findViewById(R.id.welcome_text)).setText(name);
		
		Button randomButton = (Button) findViewById(R.id.random_button);
		randomButton.setOnClickListener(new Button.OnClickListener() {
		    public void onClick(View v) {
				TextView textName = (TextView) findViewById(R.id.text_info);
				int rand = new Random().nextInt(infoArray.length);
		    	textName.setText(infoArray[rand]);
		    }
		});
	}

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.info, menu);
		return true;
	}

}
